<template>
    <div class="main">
        <div class="row">
            <div class="mui-input-row mui-search">
                <input type="search" v-model="key" class="mui-input-clear" placeholder="" @keyup.Enter="search()">
            </div>
            <ul  v-for="(item,index) in search(key) ">
                <li class="col-xs-6">
                    <router-link class="thumbnail" :to="'/particulars/'+item.id">
                        <img :src="item.img_url" height="580" width="580"/>
                        <div class="caption">
                            <h5 :title="item.title">{{item.title}}</h5>
                            <p><span style="text-decoration:line-through;">￥{{item.market_price}}</span>    
                            ￥{{item.sell_price}}</p>       
                                             </div>
                    </router-link>
                </li>
            </ul>
            <mt-button size="large" @click="getMore($event)">查看更多</mt-button>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
          return{
              key:"",
              pageindex:1,
              list:[],
              leg:[],
          }
        },
        methods:{
            search(key){
                var arr = [];
                this.list.forEach((value)=>{
                    if(value.title.indexOf(key)!==-1){
                        arr.push(value);
                    }
                });
                return arr;
            },
            get(){
                this.$http.get("api/getgoods?pageindex="+this.pageindex).then(
                    result=>{
                    if(result.body.status==0){
                       this.list=this.list.concat(result.body.message);
                        this.leg = result.body.message;
                    }else{
                        console.log("失败");
                    }
                })
            },
            
            getMore(e){
            this.pageindex++;
            this.get();
            // console.log(this.leg);
            if(this.leg.length==5){
                 var thisDom = e.currentTarget;
                 thisDom.hidden=true;
            }
           },
        },
         created:function(){
            this.get();
        },
    }
</script>

<style scoped>
    .main{
        margin-bottom: 50px;
        text-decoration: line-through;
    }
    ul{
        padding: 0px;
        margin-top: 10px;
    }
li{
    list-style: none;
    margin: 0px;
   
} 
h5{
        width: 100%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow:ellipsis;
    }
</style>